from collections import Counter


list1 = [{'id': 0, 'name': 'Hero', 'friends': [1, 2]},
 {'id': 1, 'name': 'Dunn', 'friends': [0, 2, 3]},
 {'id': 2, 'name': 'Sue', 'friends': [0, 1, 3]},
 {'id': 3, 'name': 'Chi', 'friends': [1, 2, 4]},
 {'id': 4, 'name': 'Thor', 'friends': [3, 5]},
 {'id': 5, 'name': 'Clive', 'friends': [4, 6, 7]},
 {'id': 6, 'name': 'Hicks', 'friends': [5, 8]},
 {'id': 7, 'name': 'Devin', 'friends': [5, 8]},
 {'id': 8, 'name': 'Kate', 'friends': [6, 7, 9]},
 {'id': 9, 'name': 'Klein', 'friends': [8]},
 {'id': 10, 'name': 'Jen', 'friends': []}]



users = [{'id': 0,
  'name': 'Hero',
  'friends': [1, 2],
  'friends_2': [3],
  'hobby': ['Hadoop',
   'Big Data',
   'HBase',
   'Java',
   'Spark',
   'Storm',
   'Cassandra']},
 {'id': 1,
  'name': 'Dunn',
  'friends': [0, 2, 3],
  'friends_2': [4],
  'hobby': ['NoSQL', 'MongoDB', 'Cassandra', 'HBase', 'Postgres']},
 {'id': 2,
  'name': 'Sue',
  'friends': [0, 1, 3],
  'friends_2': [4],
  'hobby': ['Python',
   'scikit-learn',
   'scipy',
   'numpy',
   'statsmodels',
   'pandas']},
 {'id': 3,
  'name': 'Chi',
  'friends': [1, 2, 4],
  'friends_2': [0, 5],
  'hobby': ['R', 'Python', 'statistics', 'regression', 'probability']},
 {'id': 4,
  'name': 'Thor',
  'friends': [3, 5],
  'friends_2': [1, 2, 6, 7],
  'hobby': ['machine learning', 'regression', 'decision trees', 'libsvm']},
 {'id': 5,
  'name': 'Clive',
  'friends': [4, 6, 7],
  'friends_2': [8, 3],
  'hobby': ['Python', 'R', 'Java', 'C++', 'Haskell', 'programming languages']},
 {'id': 6,
  'name': 'Hicks',
  'friends': [5, 8],
  'friends_2': [9, 4, 7],
  'hobby': ['statistics', 'probability', 'mathematics', 'theory']},
 {'id': 7,
  'name': 'Devin',
  'friends': [5, 8],
  'friends_2': [9, 4, 6],
  'hobby': ['machine learning', 'scikit-learn', 'Mahout', 'neural networks']},
 {'id': 8,
  'name': 'Kate',
  'friends': [6, 7, 9],
  'friends_2': [5],
  'hobby': ['neural networks',
   'deep learning',
   'Big Data',
   'artificial intelligence']},
 {'id': 9,
  'name': 'Klein',
  'friends': [8],
  'friends_2': [6, 7],
  'hobby': ['Hadoop', 'Java', 'MapReduce', 'Big Data']},
 {'id': 10, 'name': 'Jen', 'friends': [], 'friends_2': [], 'hobby': []}]


def most_common_interests_with(user_id):
    user_hobby = users[user_id]['hobby']
    dict_count = []
    for user in users:
        if user['id'] == user_id:
            continue
        temp_len = len(set(user_hobby) & set(user['hobby']))
        dict_count.append((user['id'], temp_len))
    dict_count = sorted(dict_count, key=lambda item: item[1])
    print(dict_count)
    return dict_count


abc = most_common_interests_with(3)

Counter(abc)

